using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace MapTestFramework.Common
{
    internal static class ExceptionHelper
    {
        public static void CheckEmptyOrNullValue(string value, string paramName)
        {
            if (string.IsNullOrEmpty(value))
                throw new ArgumentException(
                    ExceptionHelper.GetErrorMessage(
                        Properties.Resources.ErrorMessageNullOrEmpty
                        ),
                    paramName
                    );
        }
        public static void CheckMapTestCaseCollection(MapTestCases collection, string paramName)
        {
            if (collection.SourceTestCaseValues.Count !=
                collection.ExpectedTestCaseValues.Count)
                throw new ArgumentException(
                    Properties.Resources.ErrorMessageInvalidTestCaseCount, 
                    paramName
                    );
            return;
        }
        public static void CheckValues(string[] values, int xpathCount, string paramName)
        {
            if ((values != null) && (values.Length != xpathCount))
                throw new ArgumentException(
                    Properties.Resources.ErrorMessageInvalidValueCount, paramName
                    );
            return;
        }
        public static void CheckXPaths(string[] xpaths)
        {
            CheckXPaths(xpaths, "xpaths");
            return;
        }
        public static void CheckXPaths(string[] xpaths, string paramName)
        {
            if (xpaths == null)
                throw new ArgumentNullException(paramName);

            foreach (string xpath in xpaths)
                if (string.IsNullOrEmpty(xpath))
                    throw new ArgumentException(
                        Properties.Resources.ErrorMessageXPathExpressionNullOrEmpty, 
                        paramName
                        );
            return;
        }
        public static string GetErrorMessage(string message, params string[] args)
        {
            return string.Format(CultureInfo.CurrentUICulture, message, args);
        }
    }
}
